package Eyjafjalla.relic;

import Eyjafjalla.action.DrawToCloudAction;
import Eyjafjalla.effect.MarkFireBreathEffect;
import Eyjafjalla.helper.StringHelper;
import Eyjafjalla.modcore.EyjafjallaTag;
import Eyjafjalla.modifier.FireMarkMod;
import Eyjafjalla.patch.CloudPatch;
import basemod.abstracts.CustomRelic;
import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.actions.common.RelicAboveCreatureAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardBrieflyEffect;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Random;

public class WarmFire extends CustomRelic {

    public static final String ID = "eyjafjalla:WarmFire";

    public WarmFire(){
        super(ID, ImageMaster.loadImage(StringHelper.getRelicIMGPATH(ID,false)),ImageMaster.loadImage(StringHelper.getRelicIMGPATH(ID,true)),RelicTier.COMMON,LandingSound.SOLID);
    }

    @Override
    public void onEquip() {
        ArrayList<AbstractCard> firableCards = new ArrayList<>();
        Iterator var2 = AbstractDungeon.player.masterDeck.group.iterator();

        while (var2.hasNext()) {
            AbstractCard c = (AbstractCard) var2.next();
            if ((c.type == AbstractCard.CardType.ATTACK || c.type == AbstractCard.CardType.SKILL || c.type == AbstractCard.CardType.POWER) && (!CloudPatch.CloudField.isFire.get(c)||c.hasTag(EyjafjallaTag.UNLIMITED_FIRE_EYJAFJALLA)) && CloudPatch.CloudField.showFire.get(c)) {
                firableCards.add(c);
            }
        }

        Collections.shuffle(firableCards, new Random(AbstractDungeon.miscRng.randomLong()));
        if (!firableCards.isEmpty()) {
            CardModifierManager.addModifier(firableCards.get(0), new FireMarkMod());
            AbstractCard c = firableCards.get(0).makeStatEquivalentCopy();
            if(firableCards.size()==1)
                AbstractDungeon.topLevelEffects.add(new ShowCardBrieflyEffect(c));
            else
                AbstractDungeon.topLevelEffects.add(new ShowCardBrieflyEffect(c, (float)Settings.WIDTH / 2.0F - AbstractCard.IMG_WIDTH / 2.0F - 20.0F * Settings.scale, (float)Settings.HEIGHT / 2.0F));
            AbstractDungeon.topLevelEffects.add(new MarkFireBreathEffect(c));
            if(firableCards.size()>1){
                CardModifierManager.addModifier(firableCards.get(1),new FireMarkMod());
                c = firableCards.get(1).makeStatEquivalentCopy();
                AbstractDungeon.topLevelEffects.add(new ShowCardBrieflyEffect(c,(float) Settings.WIDTH / 2.0F + AbstractCard.IMG_WIDTH / 2.0F + 20.0F * Settings.scale, (float)Settings.HEIGHT / 2.0F));
                AbstractDungeon.topLevelEffects.add(new MarkFireBreathEffect(c));
            }
        }
        CardCrawlGame.sound.playA("ATTACK_FIRE", 0.3F);
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[0];
    }

    @Override
    public AbstractRelic makeCopy() {
        return new WarmFire();
    }
}


